((expr)=>{
    let isLoad=/(http[s]:\/\/)|(\/\/)/;
    function get_url(url){
        if(chrome.extension){
            return isLoad.test(url)?url:chrome.extension.getURL(url);
        }
        return url;
    }
    function html_load(rex, callback) {
        let timer = setInterval(() => {
            if ($(rex).length > 0) {
                clearInterval(timer);
                callback && callback($(rex));
            }
        }, 10)
    }
    function html_js_eval(url,noEval=false) {
        let js = '';
        $.ajax({
            url: get_url(url),
            dataType: 'text',
            async: false,
            success(par_js) {
                js = par_js;
                if(!noEval){
                    try {
                        (function(){
                            window.eval(js);
                        }).call(window);
                    } catch (e) {
                        console.error(e);
                    }
                }
            }
        });
        return js;
    }
    function html_get(url) {
        let html = '';
        $.ajax({
            url:get_url(url),
            dataType: 'text',
            async: false,
            cache:false,
            success(ht) {
                html = ht;
            }
        });
        return html;
    }
    function css_load(url) {
        html_load('head', ($dom) => {
            $dom.append($('<link rel="stylesheet" href="' + get_url(url) + '">'))
        })
    }
    function loadVue(name,moduleUrl){
        expr.loading && expr.loading(true);
        info.postMessage('load_vue',moduleUrl,(data)=>{
            if(data){
                //解析
                try{
                    let html=$(data);
                    function vueInit(vueTemplate){
                        vueTemplate.template=html.siblings('template').html();
                        Vue.component(name,vueTemplate);
                        expr.loading && expr.loading(false);
                    }
                    eval(html.siblings('script').html());
                }catch (e) {
                    console.log('ZY_ERR',e);
                    expr.error && expr.error(moduleUrl);
                    expr.loading && expr.loading(false);
                }
            }else{
                expr.error && expr.error(moduleUrl);
                expr.loading && expr.loading(false);
            }
        });
    }
    expr.load_js=html_js_eval;
    expr.load_html=html_get;
    expr.load_css=css_load;
    expr.loadVue=loadVue;
})(window.zLoad={},window);

